# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=furnace
pkgver=0.6
pkgrel=1
pkgdesc='A multi-system chiptune tracker compatible with DefleMask modules'
arch=('loong64' 'x86_64')
url='https://github.com/tildearrow/furnace'
license=('GPL2')
depends=(
  'glibc'
  'gcc-libs'
  'alsa-lib'
  'hicolor-icon-theme'
  'sdl2'
  'libsndfile'
  'fmt'
  'rtmidi'
  'fftw'
  'zlib'
  'libglvnd'
  'portaudio'
)
makedepends=(
  'git'
  'cmake'
  'jack'
)
optdepends=('jack: JACK audio support')
_commit='fbc34fae02b2751b1ca21d71cac74af5e7aa24dd'
source=(
  "$pkgname::git+$url#commit=$_commit"
  'github.com-superctr-adpcm::git+https://github.com/superctr/adpcm'
)
b2sums=('SKIP'
        'SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed -e 's/^v//'
}

prepare() {
  cd "$pkgname"

  # prepare git submodules
  git submodule init extern/adpcm
  git config submodule.extern/adpcm.url "$srcdir/github.com-superctr-adpcm"
  git -c protocol.file.allow=always submodule update
}

build() {
  cmake \
    -S "$pkgname" \
    -B build \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D BUILD_GUI=ON \
    -D SYSTEM_FFTW=ON \
    -D SYSTEM_FMT=ON \
    -D SYSTEM_LIBSNDFILE=ON \
    -D SYSTEM_PORTAUDIO=ON \
    -D SYSTEM_RTMIDI=ON \
    -D SYSTEM_ZLIB=ON \
    -D SYSTEM_SDL2=ON \
    -D WITH_JACK=ON

  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build  
}
